/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.fee.core.service.processor.rule;

import cn.hutool.core.util.StrUtil;
import info.peigen.hotpot.business.fee.core.service.processor.base.AbstractFeeServiceProcessor;
import info.peigen.hotpot.business.fee.facade.command.order.rule.FeeRuleDeleteOrder;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import org.noear.solon.annotation.Component;


/**
 * <b>(FeeRuleDeleteProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/6/1
 */
@SuppressWarnings("rawtypes")
@Component
public class FeeRuleDeleteProcessor extends AbstractFeeServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 20;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        FeeRuleDeleteOrder order = (FeeRuleDeleteOrder) serviceContext.getOrder();
        if (StrUtil.isNotEmpty(order.getCustomerId())) {
            feeRepository.getFeeRuleRepository().getMapper().deleteByAccountId(order.getCustomerId());
        }

        if (StrUtil.isNotEmpty(order.getRuleId())) {
            feeRepository.getFeeRuleRepository().getMapper().deleteByRuleId(order.getRuleId());
        }
        serviceContext.getResult().setSuccessNotFee();
    }
}
